package com.krmes.mes.api.remote;

import android.util.Log;

import com.krmes.mes.api.BaseCallback;
import com.krmes.mes.api.OkHttpHelper;
import com.loopj.android.http.AsyncHttpResponseHandler;
import com.loopj.android.http.RequestParams;

import java.io.UnsupportedEncodingException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;

import cz.msebera.android.httpclient.NameValuePair;
import cz.msebera.android.httpclient.client.entity.UrlEncodedFormEntity;
import cz.msebera.android.httpclient.message.BasicNameValuePair;


public class ServerOkHttpApi {

    public static void login(String userid, String password, String devid, BaseCallback callback) {
        Map<String ,String> params = new HashMap<String ,String>();
        params.put("userid", String.valueOf(userid)));
        params.put("password", String.valueOf(password)));
        params.put("devid", String.valueOf(devid)));
        //params.put("mobileLogin", "1"));
        Log.d("userid",String.valueOf(userid));
        Log.d("password",String.valueOf(password));
  
        OkHttpHelper.getinstance().post("/sys/user/login",params,callback);

    }

    public static void login2(String userid, String password, String devid,String appcode,String version, BaseCallback callback) {

        Map<String ,String> params = new HashMap<String ,String>();
        params.put("userid", String.valueOf(userid));
        params.put("password",String.valueOf(password));
        params.put("devid",String.valueOf(devid));
        params.put("appcode",String.valueOf(appcode));
        params.put("version",String.valueOf(version));

        OkHttpHelper.getinstance().post("/sys/user/login2",params,callback);
    }

    public static void changePwd(String userid, String pwdwas, String pwdnew, String pwdcof, BaseCallback callback) {
        Map<String ,String> params = new HashMap<String ,String>();
        params.put("userid", String.valueOf(userid)));
        params.put("pwdwas", String.valueOf(pwdwas)));
        params.put("pwdnew", String.valueOf(pwdnew)));
        params.put("pwdcof", String.valueOf(pwdcof)));
        Log.d("userid",String.valueOf(userid));
        Log.d("pwdwas",String.valueOf(pwdwas));
        Log.d("password",String.valueOf(pwdnew));
       
        OkHttpHelper.getinstance().post("/sys/user/changePwd",params,callback);
    }

    public static void logout(String userid, String devid, BaseCallback callback) {
        Map<String ,String> params = new HashMap<String ,String>();
        params.put("userid", String.valueOf(userid)));
        params.put("devid", String.valueOf(devid)));

        OkHttpHelper.getinstance().post("/user/loginout",params,callback);
    }

    public static void getReasonCode(String key, BaseCallback callback) {
        Map<String ,String> params = new HashMap<String ,String>();
        params.put("key", String.valueOf(key)));

        OkHttpHelper.getinstance().post("/cms/dataType/getByType",params,callback);
    }

    public static void getBykeyfield(String keyfield, BaseCallback callback) {
        Map<String ,String> params = new HashMap<String ,String>();
        params.put("keyfield", String.valueOf(keyfield)));

        OkHttpHelper.getinstance().post("/cms/taskOperation/getTask",params,callback);
    }

    public static void checkAppVer(String appcode,String version, BaseCallback callback) {
        Map<String ,String> params = new HashMap<String ,String>();
        params.put("appcode", String.valueOf(appcode)));
        params.put("version", String.valueOf(version)));

        OkHttpHelper.getinstance().post("/FileUpload/checkAppVer",params,callback);
    }
    public static void getBykeyGroup(String keyfield,String userid, BaseCallback callback) {
        Map<String ,String> params = new HashMap<String ,String>();
        params.put("keyfield", String.valueOf(keyfield)));

        OkHttpHelper.getinstance().post("/cms/taskGroup/getById",params,callback);
//        RequestParams p = new RequestParams();
//        p.add("id",keyfield);
//        p.add("userid",userid);
//        ApiHttpClient.get("/cms/taskGroup/getById",p, handler);
    }


    //产品id
    public static void getBykeyfieldEx(String keyfield, String userid, BaseCallback callback) {
        Map<String ,String> params = new HashMap<String ,String>();
        params.put("productid", String.valueOf(keyfield)));
        params.put("userid", String.valueOf(userid)));


        OkHttpHelper.getinstance().post("/cms/taskOperation/getTasByPN",params,callback);//productid
    }
    
    //根据groupid查找明细
    public static void getByGroupIdStart(String groupid, String userid, BaseCallback callback) {
        Map<String ,String> params = new HashMap<String ,String>();
        params.put("groupid", String.valueOf(groupid)));
        params.put("userid", String.valueOf(userid)));


        OkHttpHelper.getinstance().post("/cms/taskOperation/getByGroupIdStart",params,callback);//groupid
    }
    //根据groupid查找明细
    public static void getByGroupIdEnd(String groupid, String userid, BaseCallback callback) {
        Map<String ,String> params = new HashMap<String ,String>();
        params.put("groupid", String.valueOf(groupid)));


        OkHttpHelper.getinstance().post("/cms/taskOperation/getByGroupIdEnd",params,callback);//groupid
    }

    //产品id
    //已登记有用户 未完成 没被冻结 ispartcompl
    //限制条件有：产品id 用户id   任务未完成istaskcomp=false  产品是否合格 isok=false(合格) true(不合格)
    public static void getByprodidEx(String prodid, String userid, BaseCallback callback) {
        Map<String ,String> params = new HashMap<String ,String>();
        params.put("productid", String.valueOf(prodid)));
        params.put("userid", String.valueOf(userid)));


        OkHttpHelper.getinstance().post("/cms/taskOperation/getByPNAndT",params,callback);//productid
    }

    //产品id
    //
    //限制条件有：无
    public static void getByProdid(String prodid, String userid, BaseCallback callback) {
        Map<String ,String> params = new HashMap<String ,String>();
        params.put("productid", String.valueOf(prodid)));
        params.put("userid", String.valueOf(userid)));


        OkHttpHelper.getinstance().post("/cms/taskOperation/getByProdid",params,callback);//productid
    }
    //产品id
    //
    //限制条件有：无
    public static void getByProdid2(String prodid, String userid, BaseCallback callback) {
        Map<String ,String> params = new HashMap<String ,String>();
        params.put("productid", String.valueOf(prodid)));
        params.put("userid", String.valueOf(userid)));


        OkHttpHelper.getinstance().post("/cms/taskOperation/getByProdid2",params,callback);//productid
    }

    //关键字段
    public static void checkindata(String keyfieldid, String userid, BaseCallback callback) {
        Map<String ,String> params = new HashMap<String ,String>();
        params.put("userid", userid+","+keyfieldid));
        //params.put("query1", String.valueOf(keyfieldid)));


        OkHttpHelper.getinstance().post("/cms/taskOperation/checkindata",params,callback);
//        RequestParams p = new RequestParams();
////        p.add("userid",userid);
////        p.add("keyfieldid",keyfieldid);
//        p.add("query1", userid+","+keyfieldid);
//        ApiHttpClient.get("/cms/taskOperation/checkindata", p, handler);
    }


    public static void startGroup(String keyfield, String userid, int force, BaseCallback callback) {
        Map<String ,String> params = new HashMap<String ,String>();
        params.put("keyfield", String.valueOf(keyfield)));
        params.put("userid", String.valueOf(userid)));
        params.put("force", String.valueOf(force)));

        OkHttpHelper.getinstance().post("/cms/taskGroup/start",params,callback);
    }
    public static void completeGroup(String keyfield, String userid, int update, BaseCallback callback) {
        Map<String ,String> params = new HashMap<String ,String>();
        params.put("keyfield", String.valueOf(keyfield)));
        params.put("userid", String.valueOf(userid)));
        params.put("force", String.valueOf(update)));

        OkHttpHelper.getinstance().post("/cms/taskGroup/complete",params,callback);
    }

    public static void start(String keyfield, String userid, int force, BaseCallback callback) {
        Map<String ,String> params = new HashMap<String ,String>();
        params.put("keyfield", String.valueOf(keyfield)));
        params.put("userid", String.valueOf(userid)));
        params.put("force", String.valueOf(force)));

        OkHttpHelper.getinstance().post("/cms/taskOperation/start",params,callback);
    }

    public static void complete(String keyfield, String userid, int update, BaseCallback callback) {
        Map<String ,String> params = new HashMap<String ,String>();
        params.put("keyfield", String.valueOf(keyfield)));
        params.put("userid", String.valueOf(userid)));
        params.put("update", String.valueOf(update)));

        OkHttpHelper.getinstance().post("/cms/taskOperation/complete",params,callback);
    }



    public static void upload(String keyfield, String userid, String src, BaseCallback callback) {
        Map<String ,String> params = new HashMap<String ,String>();
        params.put("keyfield", String.valueOf(keyfield)));
        params.put("userid", String.valueOf(userid)));
        params.put("src", String.valueOf(src)));

        OkHttpHelper.getinstance().post("/cms/taskOperation/uploadrecord",params,callback);
    }
    public static void productcomplete(String keyfield, String userid, int update, BaseCallback callback) {
        Map<String ,String> params = new HashMap<String ,String>();
        params.put("keyfield", String.valueOf(keyfield)));
        params.put("userid", String.valueOf(userid)));
        params.put("update", String.valueOf(update)));

        OkHttpHelper.getinstance().post("/cms/taskOperation/prodcomplete",params,callback);
    }

    public static void back(String keyfield, String userid, String reason, String valuea, BaseCallback callback) {
        Map<String ,String> params = new HashMap<String ,String>();
        params.put("keyfield", String.valueOf(keyfield)));
        params.put("userid", String.valueOf(userid)));
        params.put("reason", String.valueOf(reason)));
        params.put("valuea", String.valueOf(valuea)));

        OkHttpHelper.getinstance().post("/cms/taskOperation/back",params,callback);
    }
    //未实现
    public static void productback(String keyfield, String userid, String reason, String valuea, BaseCallback callback) {
        Map<String ,String> params = new HashMap<String ,String>();
        params.put("keyfield", String.valueOf(keyfield)));
        params.put("userid", String.valueOf(userid)));
        params.put("reason", String.valueOf(reason)));
        params.put("valuea", String.valueOf(valuea)));

        OkHttpHelper.getinstance().post("/cms/taskOperation/productback",params,callback);
    }

    public static void getByProduct(String productid, BaseCallback callback) {
        Map<String ,String> params = new HashMap<String ,String>();
        params.put("productid", String.valueOf(productid)));

        OkHttpHelper.getinstance().post("/cms/taskOperation/getProduct",params,callback);
    }

    public static void productok(String productid, String userid, String reason, BaseCallback callback) {
        Map<String ,String> params = new HashMap<String ,String>();
        params.put("productid", String.valueOf(productid)));
        params.put("reason", String.valueOf(reason)));
        params.put("userid", String.valueOf(userid)));

        OkHttpHelper.getinstance().post("/cms/taskOperation/productok",params,callback);
    }
    public static void productok2(String productid, String userid, String reason, BaseCallback callback) {
        Map<String ,String> params = new HashMap<String ,String>();
        params.put("productid", String.valueOf(productid)));
        params.put("reason", String.valueOf(reason)));
        params.put("userid", String.valueOf(userid)));

        OkHttpHelper.getinstance().post("/cms/taskOperation/productok2",params,callback);
    }
    public static void productnotok(String productid, String userid, String reason,String comment, BaseCallback callback) {
        Map<String ,String> params = new HashMap<String ,String>();
        params.put("productid", String.valueOf(productid)));
        params.put("reason", String.valueOf(reason)));
        params.put("userid", String.valueOf(userid)));
        params.put("comment", String.valueOf(comment)));

        OkHttpHelper.getinstance().post("/cms/taskOperation/productnotok",params,callback);
    }
    public static void productnotok2(String productid, String userid, String reason,String comment, BaseCallback callback) {
        Map<String ,String> params = new HashMap<String ,String>();
        params.put("productid", String.valueOf(productid)));
        params.put("reason", String.valueOf(reason)));
        params.put("userid", String.valueOf(userid)));
        params.put("comment", String.valueOf(comment)));

        OkHttpHelper.getinstance().post("/cms/taskOperation/productnotok2",params,callback);
    }
    public static void getYeardata(String userid, BaseCallback callback) {
        Map<String ,String> params = new HashMap<String ,String>();
        params.put("userid", String.valueOf(userid)));

        OkHttpHelper.getinstance().post("/cms/taskOperation/getYeardata",params,callback);
    }

    public static void suredata(String userid, int month, int count, Double gdp, BaseCallback callback) {
        Map<String ,String> params = new HashMap<String ,String>();
        params.put("userid", String.valueOf(userid)));
        params.put("month", String.valueOf(month)));
        params.put("count", String.valueOf(count)));
        params.put("gdp", String.valueOf(gdp)));

        OkHttpHelper.getinstance().post("/cms/taskOperation/suredata",params,callback);
    }

    public static void addTaskOprEx2(String ids,String userid, BaseCallback callback) {
        Map<String ,String> params = new HashMap<String ,String>();
        params.put("ids", String.valueOf(ids)));
        params.put("userid", String.valueOf(userid)));

        OkHttpHelper.getinstance().post("/cms/taskOperation/addTaskOprEx2",params,callback);
    }

    public static void getMonthdata(String userid, BaseCallback callback) {
        Map<String ,String> params = new HashMap<String ,String>();
        params.put("userid", String.valueOf(userid)));

        OkHttpHelper.getinstance().post("/cms/taskOperation/getMonthdata",params,callback);
    }

    public static void getDaydata(String userid, BaseCallback callback) {
        Map<String ,String> params = new HashMap<String ,String>();
        params.put("userid", String.valueOf(userid)));

        OkHttpHelper.getinstance().post("/cms/taskOperation/getDaydata",params,callback);
    }

    public static void getnostartdata(String userid, BaseCallback callback) {
        Map<String ,String> params = new HashMap<String ,String>();
        params.put("userid", String.valueOf(userid)));

        OkHttpHelper.getinstance().post("/cms/taskOperation/getnostartdata",params,callback);
    }
    public static void getisstartnoend(String userid, BaseCallback callback) {
        Map<String ,String> params = new HashMap<String ,String>();
        params.put("userid", String.valueOf(userid)));

        OkHttpHelper.getinstance().post("/cms/taskOperation/getisstartnoend",params,callback);
    }

    public static void gettodaydtlbyuserid(String today,String userid, BaseCallback callback) {
        Map<String ,String> params = new HashMap<String ,String>();
        params.put("today", String.valueOf(today)));
        params.put("userid", String.valueOf(userid)));

        OkHttpHelper.getinstance().post("/cms/taskOperation/gettodaydtlbyuserid",params,callback);
    }
    public static void uploadFile(RequestParams params, BaseCallback callback) {
        //OkHttpHelper.getinstance().post2("/FileUploadServlet", params, handler);
        //OkHttpHelper.getinstance().post("/FileUpload/upload", params, handler);

        OkHttpHelper.getinstance().post("/FileUpload/springUpload", params, handler);
    }

    public static void uploadFile2(RequestParams params, BaseCallback callback) {
        //OkHttpHelper.getinstance().post2("/FileUploadServlet", params, handler);
        //OkHttpHelper.getinstance().post("/FileUpload/upload", params, handler);
        OkHttpHelper.getinstance().post("/FileUpload/springUpload2", params, handler);
    }

}
